package com.m1905hd.utils

import org.apache.shiro.crypto.hash.SimpleHash

/**
 *
 * @author weiwei.huang
 * @email ihuangweiwei@163.com
 * @date 15/3/31
 */
class PasswordHelper {

    private static final String ALGORITHM = "SHA-1";

    private static final int INTERATIONS = 1024;

    private static final int SALT_SIZE = 10;

    public static HashPassword encryptPassword(String plainPassword) {
        HashPassword result = new HashPassword();
        String salt = UUID.randomUUID().toString().replaceAll("-", "");
        salt = salt.substring(0, SALT_SIZE);
        SimpleHash hash = new SimpleHash(ALGORITHM, plainPassword, salt, INTERATIONS);
        result.salt = salt;
        result.password = hash.toHex();
        return result;
    }


    public static String encryptPassword(String password, String salt) {
        SimpleHash hash = new SimpleHash(ALGORITHM, password, salt, INTERATIONS);
        return hash.toHex()
    }

    public static class HashPassword {
        public String salt;
        public String password;

        @Override
        public String toString() {
            return "HashPassword{" +
                    "salt='" + salt + '\'' +
                    ", password='" + password + '\'' +
                    '}';
        }
    }


    static main(a) {
        println encryptPassword("admin")
    }

}
